package tcu.yuyp.pojo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;

@Table("invitation")    //声明该类对应数据库中的表-->实体类
//邀请函JavaBean类
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)//只返回值不是null的属性
public class Invitation {
    @Id     //声明主键id
    private Integer id;//从0开始，在发布邀请函是设置id

    private String title;//标题
    private String description;//简介
    private String user;//邀请函的创建人

    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT-8")//格式化日期
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonDeserialize(using = LocalDateDeserializer.class)//反序列化-->json对象转变为Java对象
    @JsonSerialize(using = LocalDateSerializer.class)//序列化-->Java对象转化为接送对象
    @Column("start_date")   //映射数据库中的指定列
    private LocalDate startDate;//开始日期-->使用固定的格式"yyyy-MM-dd"

    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT-8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonDeserialize(using = LocalDateDeserializer.class)
    @JsonSerialize(using = LocalDateSerializer.class)
    @Column("end_date")     //映射数据库中的指定列
    private LocalDate endDate;//结束日期-->使用固定的格式"yyyy-MM-dd"

    private Integer number;//人数
    private Integer registered;//已有人数
    private String percent;//报名人数的百分比

    @Column("names_of_invitation")      //映射数据库中的指定列
    private String[] namesOfInvitation;//报名该邀请函的人员用户名集合

    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT-8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonDeserialize(using = LocalDateDeserializer.class)
    @JsonSerialize(using = LocalDateSerializer.class)
    private LocalDate deadline;//邀请函报名截止日期

}
